import java.io.BufferedReader;
import java.io.InputStreamReader;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
    public static void main(String[] args) throws Exception{

        Gobang gb = new Gobang();
        gb.initBoard();
        gb.printBoard();
        PieceColor pc = PieceColor.BLACK;
        var br = new BufferedReader(new InputStreamReader(System.in));
        String inputStr = null;
        while((inputStr = br.readLine())!= null){

            String[] posStrArr = inputStr.split(",");
            int row = Integer.parseInt(posStrArr[0]);
            int col = Integer.parseInt(posStrArr[1]);
            if(row<1 || row >Gobang.getBoardSize())
            {
                continue;
            }
            if(col <1 || col>Gobang.getBoardSize()){
                continue;
            }
            Piece p = new Piece();
            p.setRow(row);
            p.setCol(col);

            p.setColor(pc);
            boolean placeSuccess = gb.placePiece(p);
            if(placeSuccess) {
                pc = (pc == PieceColor.BLACK ? PieceColor.WHITE : PieceColor.BLACK);
                gb.printBoard();
                System.out.println(pc.getUnicode());
                if (gb.outcome() != null) {
                    System.out.println(gb.outcome() + "赢了");
                    return;
                }
            }
        }



    }


}